<?php

date_default_timezone_set('Asia/Shanghai');
//功能：PHP利用CURL_MULTI多线程采集网页函数
$text=remote(array('http://www.phpernote.com','http://www.baidu.com/','http://www.google.com.hk/','http://www.taobao.com'));
print_r($text);
function remote($urls){
    if(!is_array($urls)||!count($urls)){
        return false;
    }
    $curl=$text=array();
    $handle=curl_multi_init();
    foreach($urls as $k=>$v){
        //$nurl[$k]=preg_replace('/([^:\/\.]+)/i',rawurlencode('\\1'),$v);
        //$curl[$k]=curl_init($nurl[$k]);
        $curl[$k]=curl_init($v);
        curl_setopt($curl[$k], CURLOPT_RETURNTRANSFER,1);
        curl_setopt($curl[$k], CURLOPT_HEADER,0);
        curl_multi_add_handle($handle,$curl[$k]);
    }
    $active = null;
    do{
        $mrc=curl_multi_exec($handle,$active);
    }while($mrc==CURLM_CALL_MULTI_PERFORM);
    while($active&&$mrc==CURLM_OK){
        if(curl_multi_select($handle)!=-1){
            do{
                $mrc=curl_multi_exec($handle,$active);
            }while($mrc==CURLM_CALL_MULTI_PERFORM);
        }
    }

    foreach($curl as $k=>$v){
        if(curl_error($curl[$k])==""){
            $text[$k]=(string)curl_multi_getcontent($curl[$k]);
        }
        curl_multi_remove_handle($handle,$curl[$k]);
        curl_close($curl[$k]);
    }
    curl_multi_close($handle);
    return $text;
}
